﻿using System;
using System.IO;

namespace ContractManager.Common.Service
{
    /// <summary>
    /// Setting helper. 
    /// </summary>
    /// <remarks>
    /// Golovkov Alex, 17.12.2010. 
    /// </remarks>
    public static class SettingHelper
    {
        #region Properties

        /// <summary> Gets the path dir. </summary>
        /// <value>   The path dir. </value>
        public static string PathDir
        {
            get
            {
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DealSystem");
            }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Creates the path dir setting. 
        /// </summary>
        /// <remarks>
        /// Golovkov Alex, 17.12.2010. 
        /// </remarks>
        public static void CreatePathDirSetting()
        {
            if (!Directory.Exists(PathDir))
            {
                Directory.CreateDirectory(PathDir);
            }
        }

        /// <summary>
        /// Deletes all layout files. 
        /// </summary>
        /// <remarks>
        /// Golovkov Alex, 17.12.2010. 
        /// </remarks>
        public static void DeleteAllLayoutFiles()
        {
            var logDir = new DirectoryInfo(PathDir);

            if (!logDir.Exists)
            {
                return;
            }

            // Get a collection of files with the same file extension
            var logFiles = logDir.GetFiles("*.dat");

            foreach (var file in logFiles)
            {
                File.Delete(file.FullName);
            }
        }

        #endregion
    }
}
